package com.atstudy.headline.web.admin.controller.tag;

import com.atstudy.headline.entity.Tags;
import com.atstudy.headline.result.Result;
import com.atstudy.headline.web.admin.service.TagsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/tags")
public class TagController {

    @Autowired
    private TagsService tagsService;

    // 获取标签列表
    @GetMapping("/list")
    public Result<List<Tags>> list() {
        List<Tags> tags = tagsService.list();
        return Result.ok(tags);
    }

    // 获取标签详情
    @GetMapping("/{id}")
    public Result<Tags> detail(@PathVariable Integer id) {
        Tags tag = tagsService.getById(id);
        return Result.ok(tag);
    }

    // 创建标签
    @PostMapping
    public Result<Void> create(@RequestBody Tags tag) {
        tagsService.save(tag);
        return Result.ok();
    }

    // 更新标签
    @PutMapping("/{id}")
    public Result<Void> update(@PathVariable Integer id, @RequestBody Tags tag) {
        tag.setTagId(id);
        tagsService.updateById(tag);
        return Result.ok();
    }

    // 删除标签 ·
    @DeleteMapping("/{id}")
    public Result<Void> delete(@PathVariable Integer id) {
        tagsService.removeById(id);
        return Result.ok();
    }

    // 新增：更新热门状态接口
    @PutMapping("/{id}/hot")
    public Result<Void> toggleHotStatus(@PathVariable Integer id, @RequestParam Boolean isHot) {
        Tags tag = new Tags();
        tag.setTagId(id);
        tag.setIsHot(isHot);
        tagsService.updateById(tag);
        return Result.ok();
    }



}